/*
 * Eugen Stoian <stoian.e@gmail.com> 2010
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


#ifndef FUNTABLE_H
#define FUNTABLE_H

#include <QStringList>
#include <QHash>
#include <MathParser_global.h>
#include <ExpressionTreeNode.h>

class FunTable
{
public:
    static void addFun(const QString& signature, MathUnaryFun fun, ExpressionTreeOp derivativeBuilder = 0);

    static MathUnaryFun fun(const QString& signature);

    static ExpressionTreeOp derivativeBuilder(const QString& signature);

    static QStringList names();

    static bool contains(const QString& signature);
protected:
    struct FunInfo {
        FunInfo(MathUnaryFun fun = 0, ExpressionTreeOp derivativeBuilder = 0){
            _fun = fun;
            _derivativeBuilder = derivativeBuilder;
        }
        bool isValid() const {
            return _fun;
        }
        MathUnaryFun fun() const {
            return _fun;
        }
        ExpressionTreeOp derivativeBuilder() const {
            return _derivativeBuilder;
        }
        MathUnaryFun _fun;
        ExpressionTreeOp _derivativeBuilder;
    };

    FunTable();

    static FunTable& instance();

    QHash <QString, FunInfo> _funHash;

};

#endif // FUNTABLE_H
